package com.ssi.mrms.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.log4j.Logger;


public class DateUtils {

	public static String DATE_FORMATE = "dd/MM/yyyy";
	public static String TIME_FORMATE = "HH:mm";
	private static final Logger logger = Logger.getLogger(DateUtils.class);
	static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMATE, Locale.US);
	static SimpleDateFormat simpleTimeFormat = new SimpleDateFormat(TIME_FORMATE, Locale.US);
	

	public static void main(String[] args) {
		
		System.out.println(": " +  DateUtils.getTimeFormate("22:25"));
	}
	public static Date getDateFormate( String ddMMyyyy){
		
		Date d = null;
		if(ddMMyyyy != null && ddMMyyyy.trim().length() >= DATE_FORMATE.length() - 2 )
		{
			try {
				d = simpleDateFormat.parse(ddMMyyyy);
			} catch (ParseException e) {
				logger.info( e.getMessage() );
			}
		}else{
			logger.info("invalid Date Formate : " + ddMMyyyy );
		}
		logger.info("Date : " + d);
		
		return d;
	}
	
	public static Date getTimeFormate( String hh_mm ){
		
		Date d = null;
		if(hh_mm != null && hh_mm.trim().length() > 0)
		{
			try {
				d = simpleTimeFormat.parse(hh_mm);
			} catch (ParseException e) {
				logger.info( e.getMessage() );
			}
		}else{
			logger.info("invalid Time Formate : " + hh_mm );
		}
		logger.info("Date : " + d);
		
		return d;
	}
	
	public static String getDateStringFormate( Date date){
		if(date != null){
			return simpleDateFormat.format(date);
		}else{
			logger.info("Null parameter");
		}
		return  null;
	}
	
}
